package com.kunyi.web.service.log.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kunyi.platform.log.entity.dto.SaveSafeDto;
import com.kunyi.platform.mybatis.KyPage;
import com.kunyi.platform.tool.util.KyAssertUtil;
import com.kunyi.web.service.log.core.transform.LogSafeTransform;
import com.kunyi.web.service.log.entity.domain.LogSafe;
import com.kunyi.web.service.log.entity.req.LogSafeListReq;
import com.kunyi.web.service.log.entity.resp.LogSafeDetailResp;
import com.kunyi.web.service.log.entity.resp.LogSafeListResp;
import com.kunyi.web.service.log.mapper.LogSafeMapper;
import com.kunyi.web.service.log.service.ILogSafeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName LogSafeServiceImpl
 * @Description log_safe业务实现
 * @Author pengjunjun
 * @Date 2024/3/6 14:30
 * @Version 1.0
 **/
@Service
public class LogSafeServiceImpl extends ServiceImpl<LogSafeMapper, LogSafe> implements ILogSafeService {

    @Override
    public Long save(SaveSafeDto saveSafe) {
        LogSafe logSafe = LogSafeTransform.save2Log(saveSafe);
        this.save(logSafe);
        return logSafe.getId();
    }

    @Override
    public PageInfo<LogSafeListResp> pageByParam(LogSafeListReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<LogSafe> list = baseMapper.listByReq(req);
        return KyPage.page(list,(item) -> LogSafeTransform.log2ListResp(item));
    }

    @Override
    public LogSafeDetailResp detailById(Long id) {
        KyAssertUtil.isTrue(id.longValue() > 0,"参数格式错误");
        LogSafe logSafe = baseMapper.selectById(id);
        KyAssertUtil.notNull(logSafe,"未找到相应日志！");
        return LogSafeTransform.log2DetailResp(logSafe);
    }
}
